
//执行上传的方法
layui.use('upload', function(){
    let upload = layui.upload;

    //执行实例
    let uploadInst = upload.render({
        elem: '#upload_button' //绑定元素
        ,url: '/upload/' //上传接口
        ,done: function(res){
            //上传完毕回调
        }
        ,error: function(){
            //请求异常回调
        }
    });
});


//懒加载图片
layui.use('flow', function() {
    let flow = layui.flow;


    function picture_generater(name,details_url,img_url) {
        let html_string = " <div class=\"layui-col-md2\" style='margin-top: 20px'>\n" +
            "                        <div class=\"layui-panel\" style=\"width: 210px;height: 250px\">\n" +
            "                            <div class=\"layui-card-header\">\n" +
            "                                <!--相册的名字-->\n" +
            "                                <a href=\""+details_url+"\">"+name+"</a>\n" +
            "                            </div>\n" +
            "                            <div class=\"layui-card-body\">\n" +
            "\n" +
            "                                <img src=\""+img_url+"\" style=\"width: 180px;height: 180px\">\n" +
            "\n" +
            "\n" +
            "                            </div>\n" +
            "                        </div>"+
            "</div>"
        return html_string
    }








    //初始加载相册的方法
    flow.load({
        elem: '#picture' //流加载容器
        , done: function (page, next) { //执行下一页的回调

            //模拟数据插入
            setTimeout(function () {
                let lis = [];
                for (let i = 0; i < 18; i++) {
                    lis.push(picture_generater(i,"","/static/img/test/IMG_1008.jpg"))
                }

                //执行下一页渲染，第二参数为：满足“加载更多”的条件，即后面仍有分页
                //pages为Ajax返回的总页数，只有当前页小于总页数的情况下，才会继续出现加载更多
                next(lis.join(''), page < 10); //假设总页数为 10
            }, 500);
        }
    });
})